﻿using EZMemoLib;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace UnitTestProject
{


    [TestClass()]
    public class ContextTest
    {


        private TestContext testContextInstance;

        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        [TestMethod()]
        public void ListCreateRemoveLoginTest()
        {

            string loginName = "Test" + DateTime.Now.ToString(); 
            string password = "123456";

            int BeforeInserting = 0;
            int AfterInserting = 0 ;
            int AfterRemoving = 0;

            var actual = Context.GetLoginList();
            Assert.IsTrue(actual != null);
            if (actual != null)
            {
                BeforeInserting  = actual.Count;
                Assert.IsTrue( BeforeInserting >= 0);
            }

            string actualLoginID;
            actualLoginID = Context.CreateLogin(loginName, password);
            Assert.IsTrue ( !string.IsNullOrEmpty ( actualLoginID ));

            actual = Context.GetLoginList();
            Assert.IsTrue(actual != null );
            if (actual != null)
            {
                AfterInserting   = actual.Count ;
                Assert.IsTrue(actual.Count > 0);
            }

            Assert.IsTrue  (BeforeInserting +1 == AfterInserting );

            string removeLoginID = Context.RemoveLogin(actualLoginID);
            Assert.IsTrue(!string.IsNullOrEmpty(removeLoginID));

            actual = Context.GetLoginList();
            Assert.IsTrue(actual != null );
            if (actual != null)
            {
                AfterRemoving = actual.Count;
                Assert.IsTrue(AfterRemoving >= 0);
            }

            Assert.IsTrue(BeforeInserting == AfterRemoving);
        }

        [TestMethod()]
        public void GetLoginListTest()
        {
            var actual = Context.GetLoginList();
            Assert.IsTrue (actual != null);
            Assert.IsTrue (actual.Count >= 0);
            
        }

    }
}
